import requests
from lxml import etree

if __name__ == "__main__":
    # ua伪装
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62"
    }
    responseText = requests.get("https://www.aqistudy.cn/historydata/", headers=headers).text
    tree = etree.HTML(responseText)
    # hotLiList = tree.xpath("//div[@class='bottom']/ul/li")
    # allList = tree.xpath("//div[@class='bottom']/ul/div[2]/li")
    # cityList = []
    # for li in hotLiList:
    #     hotName = li.xpath("./a/text()")[0]
    #     cityList.append(hotName)
    # for li in allList:
    #     cityName = li.xpath("./a/text()")[0]
    #     cityList.append(cityName)
    allList = tree.xpath("//div[@class='bottom']/ul/li/a | //div[@class='bottom']/ul/div[2]/li/a")
    cityList = []
    for li in allList:
        cityName = li.xpath("./text()")[0]
        cityList.append(cityName)
    print(cityList, len(cityList))

    # https://sc.chinaz.com/jianli/free.html

